package com.baylor.server.business.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
 

public class CommonUtils {
	
	public static final SimpleDateFormat YYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");
	public static final SimpleDateFormat YYYYlMMlDD = new SimpleDateFormat("yyyy/MM/dd");
	public static final SimpleDateFormat YYYYMMDDline = new SimpleDateFormat("yyyyMMdd");
	public static final SimpleDateFormat YYYYMMDDHHMMSS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static final SimpleDateFormat YYYYMMDDHHMMSSline = new SimpleDateFormat("yyyyMMddHHmmss");
	public static final SimpleDateFormat YYYYMMDDHHMMSSCn = new SimpleDateFormat("yyyy年MM月dd日");

	/***
	 * 转换日期格式
	 * @return
	 */
	public static String getStrDate(Date date,SimpleDateFormat format)
	{
		if(date==null)
		{
			return null;
		} 
		return format.format(date);
	}
	/***
	 * 转换日期格式
	 * @return
	 */
	public static String getStrDate(Calendar calendar,SimpleDateFormat format)
	{
		
		if(calendar==null)
		{
			return null;
		} 
		return format.format(calendar);
	}
	/**
	 * 获取今天的时间
	 * @param format
	 * @return
	 */
	public static String getToday(SimpleDateFormat format)
	{
		Calendar result = Calendar.getInstance();
		return format.format(result.getTime()); 
	}
	/**
	 * 转换date
	 * @param dateStr
	 * @param format
	 * @return
	 */
	public static String getStrDate(String dateStr,SimpleDateFormat format)
	{
		Calendar result = Calendar.getInstance();
		try {
			result.setTime(format.parse(dateStr));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			return null;
		} 
		return format.format(result.getTime());
	}
	public static String getFileName(String hkname)
	{
		String result="";
		if(StringUtils.isNotBlank(hkname))
		{
			result=	hkname.replace("*", "").replace("|", "")
					.replace("\\", "").replace(":","")
					.replace(">", "")
					.replace("?", "")
					.replace("<", "")
					.replace("/", "").replace("\"","");
		}
		return result;
	}
}
